package com.open.exam.itemmodel;

import com.open.exam.common.CommonFunction;
import com.open.exam.dto.AnswerModelWithCorr;
import com.open.exam.dto.ItemTemplate;
import com.open.exam.utils.DateUtil;
import com.openexam.openqti.openqtipaperquestion.OpenItemResult;
import com.openexam.openqti.openqtipaperquestion.OpenResultResponseVariable;
import com.openexam.openqti.openqtipaperquestion.OpenScoreOutcomeVariable;
import com.openexam.openqti.qti.BaseTypeType;
import com.openexam.openqti.qti.CardinalityType;
import com.openexam.openqti.qti.SessionStatusType;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.Date;
import java.util.List;

/**
 * @author 奶茶
 * Created by on 2017/12/14.
 * 单选题
 */
public class ItemSingleChoiceCreater extends IHtmlCreater{

    @Override
    public OpenItemResult save(ItemTemplate template) {
        //考生答案
        List<String> candidateResponses = template.getCandidateResponses();
        //正确答案
        List<String> correctResponses = template.getCorrectResponses();

        //保存作答
        OpenResultResponseVariable openResultResponseVariable = new OpenResultResponseVariable(Response, CardinalityType.SINGLE, BaseTypeType.IDENTIFIER, correctResponses, candidateResponses);

        //判分
        OpenScoreOutcomeVariable openScoreOutcomeVariable;
        if(candidateResponses != null && candidateResponses.size() > 0){
            //正确满分
            openScoreOutcomeVariable = candidateResponses.get(0).equals(correctResponses.get(0))
                    ? new OpenScoreOutcomeVariable("SCORE",template.getScore(),template.getScore())
                    : new OpenScoreOutcomeVariable(template.getScore(),0);
        }else{
            openScoreOutcomeVariable = new OpenScoreOutcomeVariable(template.getScore(), 0);
        }
        return new OpenItemResult(template.getIdentifier(), DateUtil.dateToXmlDate(new Date()),template.getSequenceIndex(), SessionStatusType.INITIAL,0,template.getMarked(), CommonFunction.getStatus(template.getItemCompletionStatus()),openResultResponseVariable,openScoreOutcomeVariable);
    }

    @Override
    public String getPreview(Boolean isShowAnswer) {
        throw new NotImplementedException();
    }

    @Override
    public List<String> getItemResult(OpenItemResult openItemResult) {
        throw new NotImplementedException();
    }

    @Override
    public double judeScore(AnswerModelWithCorr answerModel) {
        throw new NotImplementedException();
    }
}
